#include <sys/eventfd.h>
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#include <errno.h>

int main()
{
    int efd = eventfd(5, EFD_CLOEXEC | EFD_NONBLOCK); // 启用两个标志

    uint64_t val;
    for (int i = 0; i < 6; ++i)
    {
        ssize_t s = read(efd, &val, sizeof(val));

        if (s == -1)
        {
            if (errno == EAGAIN | EWOULDBLOCK)
                printf("No more events.\n");
            else
                perror("read");
        }
        else
        {
            printf("Read: %llu\n", (unsigned long long)val);
        }
    }

    close(efd);
    return 0;
}